import axios from 'axios';
import qs from 'qs';
import { reactive } from 'vue';

const instance = axios.create({
    baseURL: 'http://123.60.129.240', // 设置请求的基础URL
    timeout: 5000, // 设置请求超时时间
});

const simpleAxios = {
    async get(url, params) {
        try {
            const response = await instance.get(url, { params });
            return response.data;
        } catch (error) {
            handleRequestError(error);
            throw error;
        }
    },
    async post(url, params) {
        try {
            const response = await instance.post(url, qs.stringify(params));
            console.log(response.data);
            return response.data;
        } catch (error) {
            handleRequestError(error);
            throw error;
        }
    },
};

function handleRequestError(error) {
    // 在这里可以添加处理请求错误的逻辑
    console.error(error);
}

export const useSimpleAxios = () => {
    return reactive(simpleAxios);
};

export default simpleAxios;
